package com.dqyt.app.service;

import com.alibaba.fastjson.JSON;
import com.dqyt.app.bean.YwpAddressBean;
import com.dqyt.khjc.bean.CityBean;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.mapper.CityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AppCityService {

    @Autowired
    private CityMapper cityMapper;

    /**
     * 获取城市列表
     * @return
     */
    public ResultMsg getCityList(){

        ResultMsg ret = new ResultMsg(); // 声明一个返回值
        try{
            List<CityBean> mlist =  cityMapper.getCityList();



            List<CityBean>  province = cityMapper. getCityListBypp(0);
            List<CityBean>  city = cityMapper. getCityListBypp(1);
            List<CityBean>  district = cityMapper. getCityListBypp(2);


            YwpAddressBean ywpAddressBean = new YwpAddressBean();
            ywpAddressBean.setProvince(province);
            ywpAddressBean.setCity(city);
            ywpAddressBean.setDistrict(district);



            //System.out.println(JSON.toJSONString(ywpAddressBean));

            if(null  == mlist){
                ret.setData(new ArrayList<CityBean>());
                ret.setCode(ResultMsg.SUCESS);
            }else{
                ret.setData(mlist);
                ret.setCode(ResultMsg.SUCESS);
            }
        }catch (Exception e){
            ret.setCode(ResultMsg.ERROR);
            ret.setMsg("未知的错误，请稍候再试！");
            e.printStackTrace();
        }
        return ret;
    }


}
